package org.kur.modularization.cell;

import javafx.scene.control.*;
import javafx.scene.text.Text;
import javafx.util.Callback;
import org.kur.modularization.pojo.AllJar;

public class JarPathViewCell {
    private static Callback<TableColumn<AllJar, String>, TableCell<AllJar, String>> serialNumber;
    private static Callback<TableColumn<AllJar, String>, TableCell<AllJar, String>> jarName;
    private static Callback<TableColumn<AllJar, String>, TableCell<AllJar, String>> jarPackagePath;

    public static Callback<TableColumn<AllJar, String>, TableCell<AllJar, String>> getSerialNumber() {
        if (serialNumber == null) {
            serialNumber = new Callback<>() {
                @Override
                public TableCell<AllJar, String> call(TableColumn<AllJar, String> param) {
                    return new TableCell<>() {
                        @Override
                        protected void updateItem(String item, boolean empty) {
                            super.updateItem(item, empty);
                            if (item != null && !empty) {
                                setGraphic(new Text(String.valueOf(getIndex() + 1)));
                            }
                        }
                    };
                }
            };
        }
        return serialNumber;
    }


    public static Callback<TableColumn<AllJar, String>, TableCell<AllJar, String>> getJarName() {
        if (jarName == null) {
            jarName = new Callback<>() {
                @Override
                public TableCell<AllJar, String> call(TableColumn<AllJar, String> param) {
                    return new TableCell<>() {
                        @Override
                        protected void updateItem(String item, boolean empty) {
                            super.updateItem(item, empty);
                            if (item != null && !empty) {
                                Label jarNameLabel = new Label(item);
                                jarNameLabel.setTooltip(new Tooltip(item));
                                setGraphic(jarNameLabel);
                            }
                        }
                    };
                }
            };
        }
        return jarName;
    }

    public static Callback<TableColumn<AllJar, String>, TableCell<AllJar, String>> getJarPackagePath() {
        if (jarPackagePath == null) {
            jarPackagePath = new Callback<>() {
                @Override
                public TableCell<AllJar, String> call(TableColumn<AllJar, String> param) {
                    return new TableCell<>() {
                        @Override
                        protected void updateItem(String item, boolean empty) {
                            super.updateItem(item, empty);
                            if (item != null && !empty) {
                                Label jarPathLabel = new Label(item);
                                jarPathLabel.setTooltip(new Tooltip(item));
                                setGraphic(jarPathLabel);
                            }
                        }
                    };
                }
            };
        }
        return jarPackagePath;
    }

}
